package nl.windgazer.arachne.pages.messages;

import java.io.IOException;

import nl.windgazer.arachne.services.ArachnePrivileges;
import nl.windgazer.arachne.services.messages.MessageInterceptEventListener;
import nl.windgazer.arachne.services.messages.MessageInterceptorStorage;
import nl.windgazer.arachne.services.messages.TranslatedMessageVO;
import nl.windgazer.arachne.util.ArachneSymbolConstants;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.corelib.components.Grid;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.annotations.Symbol;

public class MessagesReview {

	//Injects and Persists

	@SuppressWarnings("unused")
	@Inject
	@Property
	private MessageInterceptEventListener _miel;
	
	@Inject
	private MessageInterceptorStorage _mis;

	@Inject
	@Symbol(ArachneSymbolConstants.TRANSLATOR_ROLE)
	private String trans_role;

	@Inject
	@Symbol(ArachneSymbolConstants.TRANSLATION_ENABLED)
	private boolean trans_enabled;

	@Inject
	private ArachnePrivileges _ap;

	//Properties and Parameters

	@SuppressWarnings("unused")
	@Property(read=true,write=true)
	private TranslatedMessageVO _mvo;

	//Components

	@SuppressWarnings("unused")
	@Component(id = "messagesGrid", parameters = {"source=miel.allTranslatedMessages", "reorder=key", "row=mvo"})
	private Grid _messagesGridComponent;

	//Events

	@OnEvent(component = "saveToLive", value = EventConstants.SUCCESS)
	void saveToLive() throws IOException {
		if (trans_enabled && _ap.hasRole(trans_role)) {
			_mis.save();
		}
	}

	//Other (check for business-logic, it should not remain here)

}
